<?php
/**
 * Created by PhpStorm.
 * User: 修
 * Date: 2015/2/14
 * Time: 18:55
 */
class Model_article extends CI_Model{
    function __construct(){
        parent::__construct();
        $this->load->database();
    }
    function all($condition=""){
        return $this->db->query("select * from article ".$condition." ORDER BY aid desc ")->result();
    }
    function add($content,$author){
        $data = array($content,$author,date("Y-m-d H:i:s"));
        return $this->db->query("insert into article (content,author,time) VALUES (?,?,?)",$data)?"true":"false";
    }
    function praise($aid){
        return $this->db->query("update article set good =good + 1 where aid = ".$aid)?"true":"false";
    }
    function nay($aid){
        return $this->db->query("update article set bad =bad + 1 where aid = ".$aid)?"true":"false";
    }
    function comment($aid,$comment){
        return $this->db->query("update article set comment = concat_ws('<>',?,comment) where aid = ?;",array($comment,$aid))?"true":"false";
    }
}